package com.itboye.lottery.activity.user

import android.content.Intent
import android.view.View
import android.widget.RelativeLayout
import com.itboye.bylibrary.listener.MyClickListener
import com.itboye.lottery.R
import com.itboye.lottery.alert.ByAlert
import com.itboye.lottery.base.BaseActivity
import com.itboye.lottery.bean.UserDataBean
import com.itboye.lottery.presenter.UserPresenter
import com.itboye.lottery.retrofit.ResponseCallback
import kotlinx.android.synthetic.main.activity_ti_xian.*

class TiXianActivity : BaseActivity(), ResponseCallback {
    private var amount: String = ""
    override fun success(o: Any, requestSuccessType: String) {
        if (requestSuccessType === userPresenter.getMyLotteryFragmentData_SUCCESS) {
            var balanceBean = o as UserDataBean
            amount = balanceBean.tixian
            tv_tixian_enable.text = (amount)
        } else if (requestSuccessType === userPresenter.getAvailableBalance_SUCCESS) {
            tv_tixian_enable.text = amount
        }
    }

    override fun fail(code: Int, msg: Any, requestErrorType: String) {
        ByAlert.alert(msg)
    }

    var rl_wx_tixian: RelativeLayout? = null
    var rl_bank_tixian: RelativeLayout? = null
    var userPresenter: UserPresenter = UserPresenter(this)
    override fun getLayoutId(): Int {
        return R.layout.activity_ti_xian
    }

    override fun initData() {
//        //先获取可提现余额
        userPresenter.getMyLotteryFragmentData()
        //获取用户可用余额
//        userPresenter.getAvailableBalance()
        rightTextValue("提现明细", MyClickListener {
            startActivity(Intent(ChongzhiActivity@ this, ChongZhi_TiXianMingXi_ZhangHuMingXi_ListActivity::class.java).putExtra("type", 4).putExtra("page", 2))
        })
    }

    override fun onClick(p0: View?) {
        when (p0) {
            rl_wx_tixian -> {
                startActivity(Intent(ChongzhiActivity@ this, TiXianDetailActivity::class.java).putExtra("amount", amount).putExtra("withdrawType",0))
            }
            rl_bank_tixian -> {
                startActivity(Intent(ChongzhiActivity@ this, TiXianDetailActivity::class.java).putExtra("amount", amount).putExtra("withdrawType",1))
            }
            else -> {
            }
        }
    }

}
